//
//  BasicTableViewController.m
//  ApexCardSDK_Demo_iOS
//
//  Created by 谭永明 on 16/9/25.
//  Copyright © 2016年 珠海艾派克科技股份有限公司. All rights reserved.
//

#import "BasicTableViewController.h"

#import "FileTableViewCell.h"
#import "BasicInformationTableViewCell.h"
#import "CommonTableViewCell.h"

@interface BasicTableViewController ()

@end

@implementation BasicTableViewController

static NSString * const WriteCardTableViewController_FileCellID = @"WriteCardTableViewController_FileCellID";
static NSString * const WriteCardTableViewController_BasicCellID = @"WriteCardTableViewController_BasicCellID";
static NSString * const WriteCardTableViewController_TotalCellID = @"WriteCardTableViewController_TotalCellID";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([FileTableViewCell class]) bundle:nil] forCellReuseIdentifier:WriteCardTableViewController_FileCellID];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([BasicInformationTableViewCell class]) bundle:nil] forCellReuseIdentifier:WriteCardTableViewController_BasicCellID];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([CommonTableViewCell class]) bundle:nil] forCellReuseIdentifier:WriteCardTableViewController_TotalCellID];
    
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 1)];
    self.tableView.tableFooterView = [[UIView alloc] init];
}

-(BOOL)shouldFileCellShowProgress {
    return NO;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSInteger num = 0;
    switch (section) {
        case 0:
            num = 1;
            break;
        case 1:
            num = self.files.count;
            break;
        case 2:
            num = 1;
        default:
            break;
    }
    return num;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = nil;
    
    switch (indexPath.section) {
        case 0:
        {
            BasicInformationTableViewCell *bCell = (BasicInformationTableViewCell *)[tableView dequeueReusableCellWithIdentifier:WriteCardTableViewController_BasicCellID forIndexPath:indexPath];
            bCell.card = self.card;
            cell = bCell;
            break;
        }
        case 1:
        {
            FileTableViewCell *fCell = (FileTableViewCell *)[tableView dequeueReusableCellWithIdentifier:WriteCardTableViewController_FileCellID forIndexPath:indexPath];
            fCell.shouldShowProgress = [self shouldFileCellShowProgress];
            fCell.file = self.files[indexPath.row];
            cell = fCell;
            break;
        }
        case 2:
        {
            CommonTableViewCell *cCell = (CommonTableViewCell *)[tableView dequeueReusableCellWithIdentifier:WriteCardTableViewController_TotalCellID forIndexPath:indexPath];
            cCell.titleLabel.text = @"总容量";
            cCell.detailComLabel.text = [NSString stringWithFormat:@"%ld Kb", (long)self.totalSize];
            cell = cCell;
            break;
        }
        default:
            break;
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.section) {
        case 0:
        {
            return 92;
            break;
        }
        case 1:
        {
            return 44;
            break;
        }
        case 2:
        {
            return 44;
            break;
        }
        default:
        {
            return 0;
            break;
        }
    }
    
    return 0;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    NSString *title = nil;
    switch (section) {
        case 0:
        {
            title = @"基本信息";
            break;
        }
        case 1:
        {
            title = @"文件列表";
            break;
        }
        case 2:
        {
            title = @"总容量";
            break;
        }
        default:
            break;
    }
    
    return title;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 1;
}

@end
